from tortoise import fields, models
from tortoise.contrib.pydantic import pydantic_model_creator


class Logs(models.Model):
    """
    The CheckDetailNum model
    """

    id = fields.IntField(pk=True)
    user = fields.CharField(max_length=30, null=False)
    logjson = fields.JSONField(null=False, default={}, description='json格式的log')
    type = fields.CharField(max_length=30, null=False, description='日志类型 目前是hdfs')
    provider = fields.CharField(max_length=30, null=False)
    create_time = fields.DatetimeField(auto_now_add=True)
    update_time = fields.DatetimeField(auto_now=True)

    # def full_name(self) -> str:
    #     """
    #     Returns the best name
    #     """
    #     if self.name or self.family_name:
    #         return f"{self.name or ''} {self.family_name or ''}".strip()
    #     return self.username

    class PydanticMeta:
        exclude = ["create_time", "update_time", "id"]

    class Meta:
        app = "db207"
        table = "logs"


Logs_Pydantic = pydantic_model_creator(Logs, name="Logs")
